package org.geektimes.projects.user.jolokia;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.management.standard.mbean.UserServiceManagement;

import javax.annotation.PostConstruct;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

public class MBeanRegister {

    @PostConstruct
    public void init() {
        try {
            MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
            ObjectName objectName = new ObjectName("jolokia:type=User");
            User user = new User();
            user.setId(1L);
            user.setEmail("1130876885@qq.com");
            user.setPassword("123456");
            user.setPhoneNumber("18956230145");
            user.setName("lanxing");
            mBeanServer.registerMBean(createUserMBean(user),objectName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private Object createUserMBean(User user) {
        return new UserServiceManagement(user);
    }

}
